/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package TestCase.InvokeStatic;

import TestCase.InstanceOf.SelfInstanceOfCheck;
import classgenerator.logic.FieldType;
import classgenerator.logic.Oracle;
import classgenerator.logic.OracleImpl;
import deadCodeRmv.StartMeDCR;
import java.util.ArrayList;
import takatuka.classreader.dataObjs.ClassFile;
import takatuka.classreader.dataObjs.MethodInfo;
import takatuka.classreader.logic.constants.FieldTypes;
import takatuka.classreader.logic.constants.JavaInstructionsOpcodes;
import takatuka.classreader.logic.factory.FactoryFacade;
import takatuka.classreader.logic.factory.FactoryPlaceholder;

/**
 *
 * @author irfan
 */
public class SimpleInvokeStaticTest extends StartMeDCR {

    public static void main(String args[]) throws Exception {
        new SimpleInvokeStaticTest().start(args);
    }

    @Override
    public void execute(String args[]) throws Exception {
        Oracle oracle = new OracleImpl();
        FactoryFacade factoryFacade = FactoryPlaceholder.getInstanceOf().getFactory();
        ClassFile cFile = oracle.createEmptyClassFile("SimpleInvokeStaticTest", "SimpleInvokeStaticTest.java");



        MethodInfo constrMethodInfo = oracle.addDefaultConstructor(cFile);


        int defaultConstrRefInfo = oracle.addMethodRefInCP(cFile, cFile.getThisClass().intValueSigned(),
                oracle.getUTF8FromCP(cFile, constrMethodInfo.getNameIndex().intValueSigned()),
                oracle.getUTF8FromCP(cFile, constrMethodInfo.getDescriptorIndex().intValueSigned()));

        int classInfo = oracle.addClassInfoInCP(cFile, oracle.addUTF8InCP(cFile, "SimpleInvokeStaticTest"));
        int myMethod = oracle.addMethodRefInCP(cFile, classInfo, "my", "()V");

           MethodInfo mainMethod = oracle.addMainFunction(cFile);
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.INVOKESTATIC,
                factoryFacade.createUn(myMethod).trim(2), mainMethod.getCodeAtt()));






        /**
         * return
         */
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.RETURN, mainMethod.getCodeAtt()));

        ArrayList<FieldType> parm = new ArrayList<FieldType>();
        parm.add(new FieldType(FieldTypes.VOID));

        FieldType ret = new FieldType(FieldTypes.VOID);

        MethodInfo myMethodInfo = oracle.addStaticFunction(cFile, "my", null, ret);
        oracle.print(cFile, myMethodInfo, "i am static Method");
        oracle.addInstruction(cFile, myMethodInfo, factoryFacade.createInstruction(JavaInstructionsOpcodes.RETURN, myMethodInfo.getCodeAtt()));







        /**
         * added the main method in the class file without any code
         */
     
        super.execute(args);
        mainMethod.getCodeAtt().setMaxLocals(1);
    }
}
